package com.thoughtworks.collection;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.*;

public class Filter {

    List<Integer>  array;

    public Filter(List<Integer> array) {
     this.array = array;
    }

    public List<Integer> filterEven() {
        List<Integer> list = new ArrayList<>();
        for (Integer arr :array) {
            if(arr%2==0){
                list.add(arr);
            }
        }
        return list;
    }

    public List<Integer> filterMultipleOfThree() {
        List<Integer> list = new ArrayList<>();
        for (Integer arr :array) {
            if(arr%3==0){
                list.add(arr);
            }
        }
        return list;
    }

    public List<Integer> getCommonElements(List<Integer> firstList, List<Integer> secondList) {
        List<Integer> list = new ArrayList<>();
        for (Integer first:firstList) {
            for (Integer second : secondList) {
                if(first==second){
                    list.add(first);
                }
            }
        }
        return list;
    }

    public List<Integer> getDifferentElements() {
        Set<Integer> middleHashSet = new HashSet<Integer>(array);
        List<Integer> afterHashSetList = new ArrayList<Integer>(middleHashSet);
        return afterHashSetList;
    }
}